<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 面板的样式放到css文件内 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>Cesium地球初始化</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }


        .toggle-switch {
            display: grid;
            grid-template-columns: 1fr 1fr;
            align-items: center;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="toggle-switch">
            <h4>第一人称模式</h4>
            <label class="switch">
                <input type="checkbox" id="mySwitch" checked onclick="toggleSwitch()">
                <span class="slider"></span>
            </label>
        </div>
    </div>
    <script>

        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']

        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;


        // 监听视口创建完成事件
        objm.viewerCreatedEvent.don((viewer) => {
            // 飞到某个视角下
            viewer.flyIn([109.605333792018, 18.53372631984145, 3796.1047515254963], [355.14016420232184, -33.81201260919955, 0.026583596819532502], 3)

            // 视口创建后,设置第一人称模式(给一个初始经纬度点位)
            viewer.changeToWalk([109.60681752569195, 18.58679192126289, 200.9999999980438226])
        })

        // 创建Cesium视口
        const viewer = objm.createCesiumViewer({
            type: 'ESCesiumViewer',
            container: document.getElementById("app"),
        });
        // viewer.ionAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyZmQzMDI1OC1kMWYyLTQ1ZjEtYTJmNS0yMjY1ZDcxZjEyOTkiLCJpZCI6NjQ3MTgsImlhdCI6MTYyOTQzNDM5M30.m8vkzG05QiAfe6JQ0XPK8z_6KuUVMf_CoSY-YlMnAIg"

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 16,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });

        // switch切换
        function toggleSwitch() {
            let switchValue = document.getElementById("mySwitch").checked;
            if (switchValue) {
                // 开启第一人称
                objm.activeViewer.changeToWalk([109.60681752569195, 18.58679192126289, 200.9999999980438226])
            } else {
                // 关闭第一人称
                objm.activeViewer.changeToMap()
            }
        }
        toggleSwitch();

    </script>
    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>